<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link href="__INDEX__/css/Phoebe.css" rel="stylesheet" />
		<link href="__INDEX__/css/all.css" rel="stylesheet" />
		<link href="__INDEX__/css/login.css" rel="stylesheet" />
		<title>注册</title>
	</head>

	<body style="margin-top: 45px;">
		<header class="mui-bar mui-bar-nav">
			<a href="javascript:history.back(-1)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<!--注册-->
		<div class="login">
			<form id='regist_form'>
				<input type="text" placeholder="手机号" id="user_tel" name="mobile" />
				<div>
					<input type="text" placeholder="验证码" id="tel_code" name='tel_code' />
					<button type="button" class="phone_code" id="yanzheng">发送验证码</button>
				</div>
				<input type="password" placeholder="输入密码" id="pwd" name="password" />
				<input type="password" placeholder="确认密码" id="cpwd" />
				<input type="text" placeholder="邀请码" id="invite_code" name="invite_code" />
				<input type="button" value="注册" class="reg_conf" />
				<p>
					<a href="login.html">已有账号，去登录</a>
				</p>
				<input type="hidden" id='user_id' name='pid'>
			</form>
		</div>
	</body>

</html>
{include file="public/footer" /}
<script>
	var onoff = true;
	//获取验证码
	$('#yanzheng').click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#user_tel").val();

		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
			type: "post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('index/index/send_msg')}",
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
				type: 1
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						$('#yanzheng').text('发送验证码');
						//定时器停了
						clearInterval(timer);
						onoff = true;
					} else {
						$('#yanzheng').text(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})
	});
</script>

<script type="text/javascript">
	
	function getUrlParam(pname) {
		var name, value;
		var str = location.href; //取得整个地址栏
		var num = str.indexOf("?")
		str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]
		var arr = str.split("&"); //各个参数放到数组里
		for(var i = 0; i < arr.length; i++) {
			num = arr[i].indexOf("=");
			if(num > 0) {
				name = arr[i].substring(0, num);
				value = arr[i].substr(num + 1);
				if(pname == name) {
					return value;
				}
			}
		}
	}
	
	$('.reg_conf').click(function() {
		$('#user_id').val(getUrlParam('user_id'));
		var pwd_1 = $('#pwd').val();
		var pwd_2 = $('#cpwd').val();
		var tuxing = $('#tuxing').val();
		var tel_code = $('#tel_code').val();
		var user_tel = $('#user_tel').val();

		if(user_tel.trim() == "") {
			layer.msg('手机号码不能为空');
			return
		}

		if(pwd_1.trim() != pwd_2.trim()) {
			layer.msg('两次密码输入不一致');
			return
		}

		if(tel_code.trim() == "") {
			layer.msg('短信验证码不能为空');
			return
		}

		$.ajax({
			url: "{:url('index/index/regist')}",
			type: 'post',
			data: $('#regist_form').serialize(), //表单数据
			success: function(data) {
				layer.msg(data.msg, {
					icon: 1,
					time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function() {
					if(data.code == 1) {
						location.href = data.url
					}
				});
			}
		});
	})

	function huan() {
		var ts = Date.parse(new Date()) / 1000;
		var img = document.getElementById('verify_img');
		img.src = "/captcha?id=" + ts;
	}
</script>